import { Injectable } from '@nestjs/common';
import { CreateBrandDto } from './dto/create-brand.dto';
import { UpdateBrandDto } from './dto/update-brand.dto';
import { Brand } from './entities/brand.entity';

@Injectable()
export class BrandService {
  create(createBrandDto: CreateBrandDto) {
    return Brand.save({
      ...createBrandDto,
      isShow: true,
      create_time: new Date(),
      update_time: new Date(),
      delete_time: null,
    });
  }

  async findAll(pageNum: number, pageSize: number) {
    const [list, count] = await Brand.findAndCount({
      skip: (pageNum - 1) * pageSize,
      take: pageSize,
    });

    return { list, count };
  }

  findOne(id: number) {
    return Brand.findOneBy({ id });
  }

  update(id: number, updateBrandDto: UpdateBrandDto) {
    return Brand.update(id, { ...updateBrandDto });
  }

  remove(id: number) {
    return Brand.update(id, { delete_time: new Date() });
  }
}
